<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
	<head>
		<meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
		<title>
			Document
		</title>
		<link rel="stylesheet" href="Public/Admin/Css/bootstrap.min.css" />
		<link rel="stylesheet" href="__PUBLIC__/Css/common.css" />
		<script type="text/javascript" src='Public/jquery-1.8.2.min.js'></script>
		<script type="text/javascript">
			$(function(){
				//先抓取组合id的name
				var specs = $('select[name="combine[]"]');
				//获得select的个数
				var len = specs.length;
				//加change(点了才发送id显示该数据)事件
				specs.change(function(){
					var remote = {
						//获取商品id
						'gid' : {{$_GET['gid']}},
						//装select里面的值,比如('红','L')
						'spec' : {}
					}

					//循环select长度
					for(var i = 0;i<len;i++){
						//判断select(i)号里面的value值==0 return 不继续往下走了
						if(specs.eq(i).val() == 0){
							return;
						}
						//把select (i) 号里面的值存到 remote.spec[i]里面
						remote.spec[i] = specs.eq(i).val();
					}
					//发送数据
					$.post("{{U('check')}}",remote,function(phpdata){

						// phpData ==0 表示数据存在
						if(phpdata == 0){
							alert('货品已存在,如果要修改库存,请点击修改');
							$('select[name="combine[]"]').val(0);
						}
					})
				})
			})
		</script>
		<style type="text/css">
		body {
			margin-bottom: 100px;
		}
		</style>
	</head>
	<body>
		<div class="container-fluid">
			<div class="row-fluid">
				<div class="span12">
					<form action="{{U('add')}}" method="post">
						<table class='table table-bordered table-hover'>
							<tr>
								<th>
									货品ID
								</th>
								{{foreach from="$arrData" key="$k" value="$v"}}
								<th>
									{{$k}}
								</th>
								{{endforeach}}
								<th>
									库存
								</th>
								<th>
									货号
								</th>
								<th>
									操作
								</th>
							</tr>
							{{foreach from="$goodsListData" value="$v"}}
							<tr class="info">
								<td>
									{{$v['glid']}}
								</td>
								{{foreach from="$v['combine']" value="$value"}}
								<td>
									{{$value}}
								</td>
								{{endforeach}}
								<td>
									{{$v['number']}}
								</td>
								<td>
									{{$v['inventory']}}
								</td>
								<td>
									<a href="{{U('edit',array('glid'=>$v['glid'],'gid'=>$gid))}}" class="btn btn-warning">
										<i class="icon-pencil icon-white">
										</i>修改
									</a>
									<a href="javascript:if(confirm('确定删除吗'))location.href='{{U('del',array('glid'=>$v['glid']))}}';" class="btn btn-danger">
										<i class="icon-trash icon-white">
										</i>删除
									</a>
								</td>
							</tr>
							{{endforeach}}
							<tr class="info">
								<td>
									添加货品
								</td>
								{{foreach from="$arrData"  key="$k" value="$v"}}
								<td>
									<select name="combine[]">
										<option value="0">
											-请选择-
										</option>
										{{foreach from="$v" key="$key" value="$value"}}
										<option value="{{$value['gaid']}}">
											{{$value['gavalue']}}
										</option>
										{{endforeach}}
									</select>
								</td>
								{{endforeach}}
								<td>
									<input type="text" name='number'  value="100" />
								</td>
								<td>
									<input type="text" name='inventory' value="{{time()}}"/>
								</td>
								<td>
									<input type="hidden" name="goods_list_gid" value="{{$_GET['gid']}}" />
								</td>
							</tr>
						</table>
						<input type="submit" value='保存添加' class="btn btn-primary"/>
					</form>
				</div>
			</div>
		</div>
	</body>
</html>